package com.ccsoft.annoreflect;

/**
 * @author chanchaw
 * @create 2022-09-23 13:03
 */
public enum OrderPolicy {
    ASC(0,"ASC"),DESC(1,"DESC")
    ;
    private int index;
    private String desc;

    // 通过枚举值获取索引
    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    OrderPolicy(int index, String desc) {
        this.index = index;
        this.desc = desc;
    }

    // 根据索引返回枚举值
    static OrderPolicy of(int index){
        for(OrderPolicy item:OrderPolicy.values()){
            if(item.getIndex() == index) return item;
        }
        return null;
    }

    public static void main(String[] args) {
        OrderPolicy orderPolicy = OrderPolicy.of(1);
        System.out.println("index:" + orderPolicy.getIndex() +",desc:"+ orderPolicy.getDesc());
    }
}
